﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;

namespace UniMana.Data
{
    public class Training_SubjectInfo
    {
        #region /*Không thay đổi*/
            public bds m_bds = new bds();
            public void Save()
            {
                m_bds.EndEdit();
                m_data.m_DCSave.SubmitChanges();
            }
            public void Delete()
            {
                m_bds.DeleteCurrent();
            }
            #endregion /*Không thay đổi*/
            private DBMain m_data = new DBMain();
            #region [Properties - Thuộc tính]
       
            public Training_Subject Properties
            {
                get { return m_bds.Current as Training_Subject; }
            }
            #endregion
            public Training_SubjectInfo(int subjectKey = 0)
            {
                var IQuery = m_data.m_DCSave.Training_Subjects.Where(tb => tb.Training_SubjectKey == subjectKey );
                m_bds.DataSource = IQuery;
                var Row = IQuery.FirstOrDefault();
                if (Row == null)
                {
                    Row = new Training_Subject();
                    m_bds.Add(Row);
                }
            }
        public IQueryable GetByKey(int subjectKey)
        {
            var l = from p in m_data.m_DCReadOnly.Training_Subjects
                    where p.Training_SubjectKey == subjectKey
                    select p;
            return l;
        }
    }
}
